package org.jeecg.modules.content.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcoding.http.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.content.entity.ConContentVersion;
import org.jeecg.modules.content.entity.ContentInfo;
import org.jeecg.modules.content.service.IConContentVersionService;
import org.jeecg.modules.content.service.IContentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
* @Description: 内容版本
* @Author: wufanxin
* @Date:   2020-06-28
* @Version: V1.0
*/
@Slf4j
@Api(tags="内容版本信息信息")
@RestController
@RequestMapping("/content/contentVersion")
public class ContentVersionController extends JeecgController<ConContentVersion, IConContentVersionService> {

   @Autowired
   private IConContentVersionService versionService;


    /**
     * 获取版本列表
     *
     * @param taskNo
     * @param req
     * @return
     */
    @AutoLog(value = "内容版本信息信息-获取版本列表")
    @ApiOperation(value="内容版本信息信息-获取版本列表", notes="内容版本信息信息-获取版本列表")
    @GetMapping(value = "/queryContentVersionList")
    public Result<?> queryContentVersionList(@RequestParam(name="taskNo") String taskNo,
                                   HttpServletRequest req) {
        QueryWrapper<ConContentVersion> versionQueryWrapper = new QueryWrapper<>();
        versionQueryWrapper.eq("task_no",taskNo).orderByDesc("create_time");
        return Result.ok(versionService.list(versionQueryWrapper));
    }




    /**
     * 获取对比信息
     *
     * @param taskNo
     * @param version1
     * @param version2
     * @param req
     * @return
     */
    @AutoLog(value = "内容版本信息信息-获取对比信息")
    @ApiOperation(value="内容版本信息信息-获取版本列表", notes="内容版本信息信息-获取版本列表")
    @GetMapping(value = "/queryContentVersionCompare")
    public Result<?> queryContentVersionCompare(@RequestParam(name="taskNo") String taskNo,
                                             @RequestParam(name="version1") String version1,
                                             @RequestParam(name="version2") String version2,
                                             HttpServletRequest req) {
        QueryWrapper<ConContentVersion> versionQueryWrapper1 = new QueryWrapper<>();
        versionQueryWrapper1.eq("task_no",taskNo).eq("create_time",version1).last(" limit 1");
        ConContentVersion versionInfo1 = versionService.getOne(versionQueryWrapper1);


        QueryWrapper<ConContentVersion> versionQueryWrapper2 = new QueryWrapper<>();
        versionQueryWrapper2.eq("task_no",taskNo).eq("create_time",version2).last(" limit 1");
        ConContentVersion versionInfo2 = versionService.getOne(versionQueryWrapper2);

        Map<String,Object> resultMap = new HashMap<>();
        resultMap.put("version1",versionInfo1);
        resultMap.put("version2",versionInfo2);
        return Result.ok(resultMap);
    }

}
